package com.liuhouse.controller;

import com.liuhouse.dto.RoleStatusDto;
import com.liuhouse.pojo.Role;
import com.liuhouse.service.IRoleService;
import com.liuhouse.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
public class RoleController {

    //操作角色需要角色的服务
    @Autowired
    private IRoleService roleService;

    //查询角色列表
    @GetMapping("/list")
    public ResponseResult list(Role role , Integer pageNum , Integer pageSize){
        return roleService.selectRolePage(role , pageNum , pageSize);
    }

    //修改角色的状态
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleStatusDto roleStatusDto){
        roleService.changeStatus(roleStatusDto);
        return ResponseResult.okResult();
    }


    @PostMapping
    //新增角色
    public ResponseResult add(@RequestBody Role role){
        roleService.insertRole(role);
        return ResponseResult.okResult();
    }


    //获取角色信息
    @GetMapping("/{roleId}")
    public ResponseResult getRole(@PathVariable("roleId") Long roleId){
        Role role = roleService.getById(roleId);
        return ResponseResult.okResult(role);
    }


    //修改角色
    @PutMapping
    public ResponseResult edit(@RequestBody Role role){
        roleService.updateRole(role);
        return ResponseResult.okResult();
    }


    //删除角色
    @DeleteMapping("/{id}")
    public ResponseResult remove(@PathVariable(name = "id") Long id){
        roleService.removeById(id);
        return ResponseResult.okResult();
    }


    //新增用户 - 查询角色列表的接口
    @GetMapping("/listAllRole")
    public ResponseResult listAllRole(){
        List<Role> roles = roleService.selectRoleAll();
        return ResponseResult.okResult(roles);
    }


}
